<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('知识库知识点管理列表')"/>
    <link th:href="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.css}" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" th:href="@{/ajax/libs/qxEasyUI/themes/default/easyui.css}">
</head>
<style>
    .combo {
        border-color: #e5e6e7;
        border-radius: 4px;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="cate-form">
                <div class="select-list">
                    <ul>
                        <li>
                            问题类别：<select name="sortbc">
                                        <option value="">请选择</option>
                                        <option th:each="cate : ${qCate}" th:text="${cate.text}"
                                                th:value="${cate.id}"></option>
                                    </select>
                        </li>
                        <li>
                            问题标题：<input type="text" name="kldgquestion"/>
                        </li>
                        <li>
                            来源部门：<input type="text" name="deptname"/>
                        </li>
                        <li>
                            录入人：<input type="text" name="inputname"/>
                        </li>
                        <li>
                            <div>
                                内容类别：<input id="contentCate"
                                                style="width:200px;height:31px;border-radius: 4px;">
                                <input id="cCateCode" name="sortac" type="hidden"/>
                                <input id="cCateName" name="sortan" type="hidden"/>
                            </div>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="resetFrom(this)"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editTab()">
                <i class="fa fa-edit"></i> 修改
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.js}"></script>
<script th:src="@{/ajax/libs/qxEasyUI/jquery.easyui.min.js}"></script>
<script th:inline="javascript">
    var editFlag = '';
    var removeFlag = '';
    var prefix = ctx + "system/kbm/point"

    $(function () {
        var options = {
            sortName:"SortBN",
            sortOrder:"desc",
            uniqueId: "myPkVal",
            url: prefix + "/kbmPointListJson",
            createUrl: prefix + "/kbmPointAdd",
            updateUrl: prefix + "/kbmPointEdit/{id}",
            removeUrl: prefix + "/kbmPointRemove/{id}",
            modalName: "知识库知识点管理",
            columns: [{
                checkbox: true
            },
                {field:'myPkVal',title:'编号',hidden:true},
                {field:'KldgNo',title:'知识编号',hidden:true},
                {field:'DeptName',title:'单位(部门)',align:'left',halign:'center'},
                {field:'KldgQuestion',title:'问题标题',align:'left',halign:'center',
                    formatter:function (value, row, index){
                        return "<span style='cursor: pointer;' title='"+value+"'>"+ value +"</span>"
                    },
                    cellStyle: cellEllipsis
                },
                {field:'KldgAnswer',title:'问题答案',align:'left',halign:'center',
                    formatter:function (value, row, index){
                        return "<span style='cursor: pointer;' title='"+value+"'>"+ value +"</span>"
                    },
                    cellStyle: cellEllipsis
                },
                {field:'InputName',title:'录入人',align:'center',halign:'center'},
                {field:'limitTime',title:'有效期限',align:'center',halign:'center',sortable:true,
                    formatter:function (value){
                        if(value != null){
                            return value.substring(0,10);
                        }
                    }
                },
                {field:'SortBN',title:'所属类别',align:'left',halign:'center'},
                {field:'OpenFlag',title:'公开',align:'center',sortable:true,
                    formatter:function (value, row, index){
                        if (value==1) {//公开
                            return "<input value=" + row.myPkVal + " name='switch' type='checkbox' checked />";
                        } else {//不公开
                            return "<input value=" + row.myPkVal + " name='switch' type='checkbox' />";
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.myPkVal + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.myPkVal + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }
            ],
            onLoadSuccess:function (){
                $("[name='switch']").bootstrapSwitch({
                    onText : "公开",
                    offText : "不公开",
                    onColor : "success",
                    offColor : "warning",
                    size : "mini",
                    // 当开关状态改变时触发
                    onSwitchChange : function(event, state) {
                        var PkId = this.value;
                        if(state == true){
                            $.modal.confirm("确认要公开该知识点吗？", function() {
                                $.operate.post(prefix + "/changeStatus", { "pkid": PkId, "openflag": 1 });
                            })
                        }else {
                            $.modal.confirm("确认要不公开该知识点吗？", function() {
                                $.operate.post(prefix + "/changeStatus", { "pkid": PkId, "openflag": 0 });
                            })
                        }
                    }
                });
            }
        };
        $.table.init(options);
    });

    $('#contentCate').combotree({
        url: ctx+'system/kbm/category/kbmContentCate',
        required: false,
        onSelect: function (record) {
            $("#cCateCode").val(record.id);
            $("#cCateName").val(record.text);
        }
    });

    function resetFrom(){
        $("#cCateCode").val("");
        $("#cCateName").val("");
        this.$.form.reset();
    }


</script>
</body>
</html>